<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>CKEDITOR.dom.node</title>
	<link rel="stylesheet" type="text/css" href="../../test.css" />
	<script type="text/javascript" src="../../../ckeditor.js"></script>
	<script type="text/javascript" src="../../test.js"></script>
	<script type="text/javascript">
	//<![CDATA[
var tc;
CKEDITOR.test.addTestCase( tc = (function()
{
	// Local reference to the "assert" object.
	var assert = CKEDITOR.test.assert;

	return {
		test_getPosition1 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'p' )[0] );

			assert.areSame( CKEDITOR.POSITION_PRECEDING, node1.getPosition( node2 ) );
		},

		test_getPosition2 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'p' )[0] );

			assert.areSame( CKEDITOR.POSITION_FOLLOWING, node2.getPosition( node1 ) );
		},

		test_getPosition3 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'p' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'b' )[0] );

			assert.areSame( CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING, node1.getPosition( node2 ) );
		},

		test_getPosition4 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'p' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'b' )[0] );

			assert.areSame( CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING, node2.getPosition( node1 ) );
		},

		test_getPosition5 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'div' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'div' )[0] );

			assert.areSame( CKEDITOR.POSITION_IDENTICAL, node1.getPosition( node2 ) );
		},

		test_getPosition6 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0].firstChild );

			assert.areSame( CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING, node1.getPosition( node2 ) );
		},

		test_getPosition7 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0].firstChild );
			assert.areSame( CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING, node2.getPosition( node1 ) );
		},

		test_getPosition8 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0].firstChild );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'b' )[0].firstChild );

			assert.areSame( CKEDITOR.POSITION_PRECEDING, node1.getPosition( node2 ) );
		},

		test_getPosition9 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0].firstChild );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'b' )[0].firstChild );

			assert.areSame( CKEDITOR.POSITION_FOLLOWING, node2.getPosition( node1 ) );
		},

		test_getPosition10 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'b' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'i' )[0] );

			assert.areSame( CKEDITOR.POSITION_PRECEDING, node1.getPosition( node2 ) );
		},

		test_getPosition11 : function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'b' )[0] );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'i' )[0] );

			assert.areSame( CKEDITOR.POSITION_FOLLOWING, node2.getPosition( node1 ) );
		},

		/**
		 *  Test 'preceding' position.
		 */
		test_getPosition_3240: function()
		{
			var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'b' )[0].firstChild );
			var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'span' )[0].firstChild );

			assert.areSame( CKEDITOR.POSITION_PRECEDING, node1.getPosition( node2 ) );
		},

		// Test get previous non-spaces node.
		test_getPrevious : function()
		{
			var element = new CKEDITOR.dom.element( document.getElementById( 'append' ) );
			var span1 = new CKEDITOR.dom.element( 'span' );
			element.append( span1 );
			element.append( new CKEDITOR.dom.text( ' ' ) );
			var span2 = new CKEDITOR.dom.element( 'span' );
			element.append( span2 );
			var previous = span2.getPrevious( CKEDITOR.dom.walker.whitespaces( true ) );
			assert.areSame( span1.$, previous.$ );
		},

		// Test get next non-spaces node.
		test_getNext : function()
		{
			var element = new CKEDITOR.dom.element( document.getElementById( 'append' ) );
			var span1 = new CKEDITOR.dom.element( 'span' );
			element.append( span1 );
			element.append( new CKEDITOR.dom.text( ' ' ) );
			var span2 = new CKEDITOR.dom.element( 'span' );
			element.append( span2 );
			var next = span1.getNext( CKEDITOR.dom.walker.whitespaces( true ) );
			assert.areSame( span2.$, next.$ );
		},

		name : document.title
	};
})() );

//window.onload = function()
//{
//	var node1 = new CKEDITOR.dom.node( document.getElementsByTagName( 'h1' )[0] );
//	var node2 = new CKEDITOR.dom.node( document.getElementsByTagName( 'p' )[0] );
//
//	alert( node1.getPosition( node2 ) );
//};
//window.onload =  tc.test_getPosition6;
	//]]>
	</script>
</head>
<body>
	<div>
		<h1>Title</h1>
		<p><b>Sample</b> <i>Text</i></p>
	</div>
	<span>Another</span>
	<p id="append"></p>
</body>
</html>
